package org.fluidripple.socket.protocol;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.ByteBufUtil;
import io.netty.channel.Channel;
import org.fluidripple.socket.operation.CKSUMCalculator;
import org.fluidripple.socket.session.Session;
import org.fluidripple.socket.session.SessionManager;
import org.fluidripple.socket.wrapper.DataWrapper;

/**
 * 设置采样模式
 */
public class DeviceCollectModelProtocol extends Protocol{
    @Override
    public void writer(Channel channel) {
        Session session = SessionManager.getSession(channel);
        session.setProtocol(this);
        byte[] bytes = ByteBufUtil.decodeHexDump("F0C104D200");
        int checksum = CKSUMCalculator.calculateChecksum(ByteBufUtil.decodeHexDump("04D200"));
        ByteBuf buffer = ByteBufAllocator.DEFAULT.buffer();
        buffer.writeBytes(bytes);
        buffer.writeByte(checksum);
        channel.writeAndFlush(buffer);
    }

    @Override
    public void toDecode(DataWrapper dataWrapper) {

    }

    public static void main(String[] args) {
        int a = 0x00;
        System.out.println(a);
    }
}
